#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <set>
#include <vector>
#include <cstdio>
#include <cmath>
#define LL long long
#define nextLine() {int c = 0; while ((c = getchar()) != EOF && c != 10);}
#define sqr(a) ((a) * (a))
#define fill(a, c) memset(a, c, sizeof a)
#define ldb long double
#define sgn(a) ((a) > eps ? 1 : -1)
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));
const int INF = 1 << 28;
const LL LINF = 1ll << 50;
const ldb LDINF = 1e70;
const ldb cos3 = cos(pi / 3);
const ldb sin3 = sin(pi / 3);
using namespace std;
#define file "c"


int edges;
int next[200010], first[200010], end[200010];
int s, n;
LL k[100010];
bool was[100010];


inline void addEdge(int i, int j)
{
	next[edges] = first[i];
	first[i] = edges;
	end[edges] = j;
	edges++;
}


void Load()
{
	cin >> n;
	int i;
	edges = 0;
	for (i = 1; i <= n; i++)
	{
		was[i] = 0;
		first[i] = -1;
		scanf("%I64d", &k[i]);
	}
	int a, b;
	for (i = 0; i < n - 1; i++)
	{
		scanf("%d%d", &a, &b);
		addEdge(a, b);
		addEdge(b, a);
	}
	cin >> s;
}

LL d[100010];
vector <pair<LL, int> > res[100010];


void dfs(int ver)
{
	was[ver] = 1;
	d[ver] = 1;
	res[ver].resize(0);
	int u;
	for (u = first[ver]; u != -1; u = next[u])
	{
		if (was[end[u]]) continue;
		dfs(end[u]);
		res[ver].push_back(make_pair(d[end[u]], end[u]));
	}
	sort(res[ver].begin(), res[ver].end());
	reverse(res[ver].begin(), res[ver].end());
	k[ver]--;
	for (int i = 0; k[ver] && i < res[ver].size(); i++)
	{
		d[ver] += res[ver][i].first + 1;
		k[ver]--;
	}
	LL t;
	for (int i = 0; i < res[ver].size() && k[ver]; i++)
	{
		t = min(k[ver], k[res[ver][i].second]);
		d[ver] += 2 * t;
		k[ver] -= t;
		k[res[ver][i].second] -= t;
	}
}

void Solve()
{
	k[s]++;
	dfs(s);
	cout << d[s] - 1;

}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	#endif
	Load();
	Solve();
	return 0;
}